#!/bin/bash
SHELL_FOLDER=$(cd $(dirname $0);pwd)

read -p "Please enter the installed version(default: v1.29.2):" VERSION

if [ -z "$VERSION" ]; then
    VERSION=v1.29.2
fi

# check version
for folder in "$SHELL_FOLDER"/*; do  
    # 判断当前项是否为文件夹  
    if [[ -d "$folder" ]]; then 
        # 判断文件夹名称是否与输入的文件夹名称匹配  
        if [[ "${folder}" == "$SHELL_FOLDER/$VERSION" ]]; then  
            found_version=true  
        fi  
    fi  
done

if [[ -z $found_version ]]; then
    echo "No version found!"
    exit 1
fi

read -p "Please enter the user name to join the compose group:" USERNAME

if [ -z "$USERNAME" ]; then
    echo "User name cannot be empty!"
    exit 1
fi

cp $SHELL_FOLDER/$VERSION/docker-compose /usr/local/bin/

chown -R $USERNAME /usr/local/bin/docker-compose

chgrp -R $USERNAME /usr/local/bin/docker-compose

